package com.hzhr.iot.web.controller;

import com.hzhr.iot.user.sdk.model.role.RoleModel;
import com.hzhr.iot.user.sdk.service.User_RoleService;
import com.hzhr.iot.web.controller.base.BaseController;
import com.hzhr.iot.web.model.response.BaseResponse;
import com.hzhr.iot.web.model.response.MapFromPageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Api(value="角色接口",description="角色接口")
@RestController
@RequestMapping("/role")
public class RoleController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    User_RoleService user_roleService;

    @ApiOperation(value = "列表", notes = "列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "uat", value = "用户登录令牌", dataType = "String", required = true, paramType = "query")
    })
    @RequestMapping(value = "/getlist", method = RequestMethod.POST)
    BaseResponse getlist(@RequestParam(value = "uat", required = true) String uat) throws Exception {
        List<Map<String, Object>> list = new ArrayList<>();

        Map<String, String> header = new HashMap<>();
        header.put("token", getToken());
        Map<String, Object> query = new HashMap<>();
        query.put("show", "list");
        query.put("show_info", true);
        List<RoleModel> roleModels = user_roleService.get1(header, query).getModelList();
        for (RoleModel roleModel :
        roleModels) {
            Map<String, Object> item1 = new HashMap<>();
            item1.put("id", roleModel.getId());
            item1.put("name", roleModel.getName());
            list.add(item1);
        }

        return new BaseResponse("0", "成功",new MapFromPageInfo<>(list));
    }
}
